#!/bin/bash -e

function info() {
    echo Usage: `basename $0` '[-r -1 -2] src_file target_file'
    exit 1
}

while getopts ":p:f:r12" opt; do
    case  $opt  in
        p) out_prefix=$OPTARG;;
        f) suffix=$OPTARG;;
        r) from_remote=true;;
        1) sg=true;;
        2) med=true;;
        *) info;;
    esac
done
shift $(($OPTIND - 1))

if [ $# -lt 1 ]; then info; fi

user_sg=sanger-dev
ip_sg=192.168.12.102
home_sg=/mnt/ilustre/users/sanger-dev/sg-users/yangfei

user_med=fei.yang
ip_med=192.168.10.113
home_med=/mnt/ilustre/users/fei.yang

if test -n "$from_remote"; then
    echo from remote to local
    if test -n "$sg"; then
        scp -rC $user_sg@$ip_sg:$home_sg/$1 $2
    elif test -n "$med"; then
        scp -rC $user_med@$ip_med:$home_med/$1 $2
    else
        scp $1 $2
    fi
else
    echo from local to remote
    if test -n "$sg"; then
        scp -rC $1 $user_sg@$ip_sg:$home_sg/$2
    elif test -n "$med"; then
        scp -rC $1 $user_med@$ip_med:$home_med/$2
    else
        scp $1 $2
    fi
fi
